import React, { PureComponent,createRef } from 'react'

// 类组件
class HelloWord extends PureComponent {
  test() {
    console.log('HelloWord Component test()');
  }
  render() {
    return <h2>Hello, World!</h2>
  }
}

export class App extends PureComponent {
  constructor() {
    super()
     this.Hwc = createRef()
  }
  getComponent() {
    console.log(this.Hwc.current);
    this.Hwc.current.test() //拿到组件实例调用组件方法
  }
  render() {
    return (
      <div>
        App
        <button onClick={e => this.getComponent()}>获取HWD组件实例</button>
        <HelloWord ref={this.Hwc } />
      </div>
    )
  }
}

export default App